{% extends 'wxchat/wxbase.html' %}{% load static %}
{% block container %}

<div class="weui-panel weui-panel_access">
    <div class="weui-panel__hd">
        <div class="weui-flex">
            <div><a href="javascript:window.history.back(-1)"><i class="icon iconfont icon-jiantou3 gray" ></i></a></div>
            <div class="weui-flex__item" style="text-align: center;"><span class="detail_title">我的购物单</span></div>
             <div ><a href="{% url 'shopping-list' %}?next={{ request.get_full_path }}"><i class="icon iconfont icon-shangcheng10 pink r" ></i></a></div>
         </div>
    </div>
    <div class="weui-panel__bd">
        <div class="weui-tab" id="navbar">
            <div class="weui-navbar">
                <div class="weui-navbar__item weui-bar__item_on"><i class="fa fa-search "></i>商品订单</div>
                <div class="weui-navbar__item"><i class="fa fa-search "></i>定制食品订单</div>
            </div>
            <div class="weui-tab__panel">
                <!--商品订单开始-->
                <div class="weui-tab__content">
                     {% for order in orders %}
                        {% for orderItem in order.items.all %}
                            <div class="weui-media-box weui-media-box_appmsg" style="background-color: #fafafa">
                                {% if orderItem.goods.images %}
                                <div class="weui-media-box__hd">
                                     <img class="weui-media-box__thumb" src="{{orderItem.goods.images.url }}" alt="">
                                </div>
                                {% endif %}
                                <div class="weui-media-box__bd">
                                    <h4 class="weui-media-box__title">{{ orderItem.goods.name }}</h4>
                                    <ul class="weui-media-box__info ">
                                        <li class="weui-media-box__info__meta sub_title">¥ {{ orderItem.goods.price }}</li>
                                        <li class="weui-media-box__info__meta r" style="color: #977a7a;" >
                                            x{{ orderItem.quantity }}
                                        </li>
                                        <li class="weui-media-box__info__meta r" style="color: #c9302c;">
                                            会员送:<span  id="card">{{ orderItem.goods.diff_price }}</span><i class="icon iconfont icon-youhuiquan1 benefits_card"></i>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        {% endfor %}
                        <div class="weui-cell cell-end">
                            <div class="weui-cell__bd color_red"  ><B>{% if order.status == 0 %} 待支付{% else %} 已支付{% endif %}</B></div>
                            <div class="weui-cell__ft " style="color:#000000" >
                                {% if is_member == 1 %}
                                <p>共 {{ order.get_total_count }} 件商品, 总价<B> ¥{{ order.get_member_total_cost }}</B></p>
                                {% else %}
                                 <p>共 {{ order.get_total_count }} 件商品, 总价 ¥{{ order.get_total_cost }}</p>
                                {% endif %}
                                {% if order.status == 0 %}
                                <span><a id="order_del{{ order.id }}" href="javascript:;" class="weui-btn weui-btn_mini weui-btn_plain-default" data-item="{{ order.out_trade_no }}">删除订单</a> </span>
                                <span><a id="gotopay{{ order.id }}" href="javascript:;" class="weui-btn weui-btn_mini weui-btn_plain-primary" data-item="{{ order.out_trade_no }}">继续支付</a></span>
                                {% endif %}
                            </div>
                        </div>
                    {% empty %}
                        <div class="weui-cell cell-end">
                            <div class="weui-cell__hd" >
                               <p>暂时无订单</p>
                            </div>
                        </div>
                    {% endfor %}
                </div>
                <!--商品订单结束-->
                <!--定制食品订单开始-->
                <div class="weui-tab__content">
                    {% for order in dogorders %}
                            <div class="weui-media-box weui-media-box_appmsg" style="background-color: #fafafa">
                                <div class="weui-media-box__bd">
                                    <h4 class="weui-media-box__title">{{ order.product_detail }}</h4>
                                    <ul class="weui-media-box__info ">
                                        <li class="weui-media-box__info__meta sub_title">¥ {{ order.price }}</li>
                                        <li class="weui-media-box__info__meta r" style="color: #977a7a;" >
                                            x{{ order.goods_nums }}
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        <div class="weui-cell cell-end">
                            <div class="weui-cell__bd color_red"  ><B>{% if order.status == 0 %} 待支付{% else %} 已支付{% endif %}</B></div>
                            <div class="weui-cell__ft " style="color:#000000" >
                                <p>共 {{ order.goods_nums }} 件商品, 总价<B> ¥{{ order.total_fee }}</B></p>
                                {% if order.status == 0 %}
                                <span><a id="dogorder_del{{ order.id }}" href="javascript:;" class="weui-btn weui-btn_mini weui-btn_plain-default" data-item="{{ order.out_trade_no }}">删除订单</a> </span>
                                <span><a id="dogorder_pay{{ order.id }}" href="javascript:;" class="weui-btn weui-btn_mini weui-btn_plain-primary" data-item="{{ order.out_trade_no }}">继续支付</a></span>
                                {% endif %}
                            </div>
                        </div>
                    {% empty %}
                        <div class="weui-cell cell-end">
                            <div class="weui-cell__hd" >
                               <p>暂时无订单</p>
                            </div>
                        </div>
                    {% endfor %}
                </div>
                <!--定制食品订单结束-->
            </div>
        </div>


    </div>

</div>

{% endblock container %}
{% block bottomjs %}

    {{ block.super }}
    <script type="application/javascript">


    $(function(){
        defIndex = sessionStorage.getItem('myorder');

        weui.tab('#navbar',{
            defaultIndex: defIndex ==null?0:defIndex,
            onChange: function(index){
                sessionStorage.setItem('myorder',index);
            }
        });


        $("a[id^='gotopay']").on('click', function(){
            let out_trade_no = $(this).attr("data-item");
            window.location.href = '{% url "create-order" %}?orderId=' + out_trade_no;
        });

        $("a[id^='order_del']").on('click', function(){
            let out_trade_no = $(this).attr("data-item");
            var params ={
              out_trade_no: out_trade_no,
              csrfmiddlewaretoken: '{{ csrf_token }}',
              action: "remove",
            };
           $.ajax({
              type: 'POST',
              url: '{% url "my-order-list" %}',
              dataType: 'json',
              data: params,
              timeout: 5000,
              success: function(data){
                  if(data.success == 'true')
                        window.location.href = '{% url "my-order-list" %}';
              },
              error: function(error){}
            });
        });
        <!--定制食品-->
        $("a[id^='dogorder_pay']").on('click', function(){
            let out_trade_no = $(this).attr("data-item");
            window.location.href = '{% url "order-list" %}?out_trade_no=' + out_trade_no;
        });

        $("a[id^='dogorder_del']").on('click', function(){
            let out_trade_no = $(this).attr("data-item");
            var params ={
              out_trade_no: out_trade_no,
              csrfmiddlewaretoken: '{{ csrf_token }}',
              action: "remove",
            };
           $.ajax({
              type: 'POST',
              url: '{% url "order-list" %}',
              dataType: 'json',
              data: params,
              timeout: 5000,
              success: function(data){
                  if(data.success == 'true')
                        window.location.href = '{% url "my-order-list" %}';
              },
              error: function(error){}
            });
        });
    });

    </script>
{% endblock bottomjs %}
